package com.lj.play;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Director {

    //构造函数注入
    @Test
    public void direct(){
        Geli geli = new LiuDeHua();
        MoAttack moAttack = new MoAttack(geli);
        moAttack.cityGateAsk();
    }

    //属性注入
    @Test
    public void direct2(){
        Geli geli = new LiuDeHua();
        MoAttack moAttack = new MoAttack();
        moAttack.setGeli(geli);
        moAttack.cityGateAsk();
    }

    //接口注入
    @Test
    public void direct3(){
        Geli geli = new LiuDeHua();
        MoAttack2 moAttack2 = new MoAttack2();
        moAttack2.findGeli(geli);
        moAttack2.cityGateAsk();
    }
    //spring配置文件 属性注入
    @Test
    public void direct4(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        MoAttack moAttack = ac.getBean("moAttack",MoAttack.class);
        moAttack.cityGateAsk();
    }
}
